package joodin.impl.util;

import joodin.impl.application.util.ApplicationWrapper;

import org.jowidgets.common.types.Markup;
import org.vaadin.cssinject.CSSInject;

import com.vaadin.ui.Component;

public class MarkupProvider {
	public static void setMarkup(final Markup markup , final Component comp){

		comp.removeStyleName("bold-" + comp.hashCode());
		comp.removeStyleName("italic-" + comp.hashCode());
		
		if (Markup.STRONG.equals(markup)) {
			String style = ".bold-" + comp.hashCode() + " { font-weight:bold;}\n";
			CSSInject css = ApplicationWrapper.getCSSInjector();
			if(!css.getValue().contains(style)){
				css.setValue(css.getValue() + style);
			}
			comp.addStyleName("bold-" + comp.hashCode());
		}
		else if (Markup.EMPHASIZED.equals(markup)) {
			String style = ".italic-" + comp.hashCode() + " { font-style:italic; }\n";
			CSSInject css = ApplicationWrapper.getCSSInjector();
			if(!css.getValue().contains(style)){
				css.setValue(css.getValue() + style);
			}
			comp.addStyleName("italic-" + comp.hashCode());
		}
	}
}
